<template>
    <div class="app-container home">
                <van-field v-model="phoneNo" label="手机号" type="number"  readonly placeholder="" />
                <van-field v-model="newPwd" label="新密码" type="password" placeholder="请输入新密码" />
                <van-field v-model="newPwdT" label="确认密码" type="password" placeholder="再次输入新密码" />
        <div class="btn">
            <van-button color="#66d6ff" @click="toIndex" type="primary" block>确 定</van-button>
        </div>
    </div>
</template>

<script setup name="resetPwdByPhone">
import JSEncrypt from 'jsencrypt'
import { showSuccessToast, showToast } from "vant"
import { loseLoginPassword } from "../../api/agent"
const route = useRoute()
const phoneNo = ref("")
const securityCode = ref("")
const newPwd = ref("")
const newPwdT = ref("")
phoneNo.value = route.query.phoneNo
securityCode.value = route.query.securityCode
const toIndex = () => {
    if (!newPwd.value) {
        showToast("请输入新密码")
        return
    }
    if (newPwd.value !== newPwdT.value) {
        showToast("两次密码不一致，请检查")
        return
    }
    const key =
        'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAicjwP+F30h1RmMZuAjKIW7+pJxK6NlhvsNks28X4/91iF7lBoZd57ZuN+310vaFxol8khFd5SDbnx7piqPxuAaUC/IygD4iPn2ZSSA5pqqdQYodJVckyh4PNjbh6lDkjYNoAGhz1BY+AiQz2uPTNFnOqmDu1ZfhoQCWMhSleW0zikybl3KRcczDja96+DmKkssXAYN5clnnZMcBjuWOwBz5pgHiQEQTatdWm/un3SR366LrnKAXYUyAEUxwuEA9qtiaDvKgLzSl84FqmvU6cLzmLJM+b+++0CONoT0IR9I6XFkF/wErnd8Y+gEB4oQEURe39BUjl5VcxSJxf1HorSQIDAQAB'
    let jse = new JSEncrypt()
    jse.setPublicKey(key)
    let payPwd = jse.encrypt(newPwd.value)
    loseLoginPassword({
        username:phoneNo.value,
        newPassword:payPwd,
        securityCode:securityCode.value,
    }).then(res=>{
        if(res.code == 200){
            showSuccessToast('重置成功')
            setTimeout(() => {
                var u = navigator.userAgent;
                var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
                var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
                if (isiOS) {
                    window.webkit.messageHandlers.returnHome().postMessage({title: '', content: '', url: ''});//ios
                } else if (isAndroid) {
                    window.android.finishFromJS();
                };
            }, 2000)
        }
    })
}
</script>

<style scoped lang="scss">
.app-container {
    padding: 10px;

    .btn {
        margin-top: 20px;
    }
}
</style>

